package com.heykui.restfulcrud.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.heykui.restfulcrud.result.CodeMsg;
import com.heykui.restfulcrud.result.Result;
import com.heykui.restfulcrud.Exception.Err;
import com.heykui.restfulcrud.Exception.Fail;
import com.heykui.restfulcrud.Exception.Suss;
import com.heykui.restfulcrud.model.User;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Res {

    @GetMapping("/news")
    public Result news(){
        List<String> list = new ArrayList<>();
        list.add("1111111");
        list.add("2222222");
        list.add("3333333");
        return Result.suss(list);
    }

    @GetMapping("/news1")
    public Result news1(){
        Map<String, String> map = new HashMap<>();
        map.put("a", "123123");
        map.put("b", "78558");
        map.put("c", "aaaaa");
        return Result.suss(map);
    }

    @GetMapping("/news2")
    public Result news2(){
        User user = new User(13, "aaa", 19);
        return Result.suss(user);
    }

    @GetMapping("/news3")
    public Result new3(){
        // User user = new User(13, "aaa", 19);

        // return Result.suss("这是返回的数据");
        // throw new Suss("123123");
        // throw new Suss(user);
        
        // return Result.fail();
        // throw new Fail();
        // throw new Fail(CodeMsg.TOKEN_MISS);
        throw new Fail(CodeMsg.TOKEN_MISS, "您老人家忘了登录了");

        // return Result.error();
        // throw new Err();
        // throw new Err("数据写入失败");
    }
}